<template>
  <div class="LangCategoryBox">
    <div class="Box">
      <div
        :class="'Item ' + (index === choolsIndex ? 'categoryAction' : '')"
        v-for="(item, index) in data"
        :key="index"
        v-items
        @click="choolsItem(index)"
        :ref="'langCategory' + index"
      >
        <span>{{ item.category_name }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    data: false
  },
  data() {
    return {
      choolsIndex: 0
    };
  },
  created() {
    if (this.$store.getters.getLangCategoryId !== false) {
      this.choolsIndex = this.$store.getters.getLangCategoryId.index;
    } else {
      let categoryItem = this.data[0];
      categoryItem['index'] = 0;
      this.$store.commit('setLangCategoryId', categoryItem);
    }
  },
  methods: {
    choolsItem(index) {
      this.choolsIndex = index;
      // 设置 vuex状态
      let categoryItem = this.data[index];
      categoryItem['index'] = index;
      this.$store.commit('setLangCategoryId', categoryItem);
    },
    moveLangCategory(index) {
      this.$service.move(this.$refs['langCategory' + index][0]);
    }
  }
};
</script>

<style lang="less" scoped>
.LangCategoryBox {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.Box {
  height: 60%;
  width: 80%;
  display: flex;
  flex-direction: row;
  background: #223c61;
  border-radius: 30px;
  padding: 4px 30px;
}
.Item {
  font-size: 20px;
  line-height: 7vh;
  text-align: center;
  color: #fff;
  padding: 4px;
  width: 12%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.categoryAction {
  border-radius: 10px;
  height: 110%;
  background: rgba(230, 0, 0, 1);
}
</style>
